#include "ProgressText.h"
#include "../../utils/StringUtil.h"

ProgressText::ProgressText()
:minValue(0)
,maxValue(0)
,curValue(0)
,m_pCount(NULL)
{
	proSize = CCSizeMake(0, 0);
}

ProgressText::~ProgressText()
{

}

void ProgressText::setProgress( float value )
{
	curValue = value;
	m_pProgress->setPercentage(value);
	m_pCount->setString(fcs(mFormatStr, value, maxValue));
}

void ProgressText::setPecent( float value )
{
	curValue = value;
	m_pProgress->setPercentage(value);
	int val = int(value/maxValue*100);
	m_pCount->setString(fcs(mFormatStr, val));
}

void ProgressText::setRect( float min, float max )
{
	this->minValue = min;
	this->maxValue = max;
}

ProgressText* ProgressText::create( const char *pszProgressFileName, const char* fontName, float fontSize )
{
	ProgressText* pProgressText = new ProgressText();
	pProgressText->initWithFile(pszProgressFileName, fontName, fontSize);
	return pProgressText;
}

void ProgressText::initWithFile( const char *pszProgressFileName, const char* fontName, float fontSize )
{
	CCSprite* pSprite = CCSprite::create(pszProgressFileName);
	CCSize size = pSprite->getContentSize();
	//proSize.setSize(size.width, size.height);
	m_pProgress = CCProgressTimer::create(pSprite);
	m_pProgress->setType(kCCProgressTimerTypeBar);
	m_pProgress->setMidpoint(ccp(0,0));
	m_pProgress->setBarChangeRate(ccp(1,0));
	m_pProgress->setPercentage(80);
	m_pCount = CCLabelTTF::create("", fontName, fontSize);
	m_pCount->setPosition(ccp(proSize.width/2, 0));
	addChild(m_pProgress);
	addChild(m_pCount);
}

void ProgressText::setFormatStr( const char* str )
{
	mFormatStr = str;
}
